package com.example.qt.ptplatform.controller;

import com.example.qt.ptplatform.entity.UserAssessment;
import com.example.qt.ptplatform.service.UserAssessmentService;
import com.example.qt.ptplatform.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user/assessment")
public class UserAssessmentController {
    @Autowired
    private UserAssessmentService userAssessmentService;

    /**
     * 获取用户的最新考核结果
     * @param userId 用户ID
     * @return 用户考核结果
     */
    @GetMapping("/latestResult")
    public JsonResult getLatestAssessmentResult(@RequestParam Integer userId) {
        try {
            UserAssessment result = userAssessmentService.getLatestAssessmentResult(userId);
            return JsonResult.success(result, "查询成功");
        } catch (Exception e) {
            return JsonResult.error("查询失败: " + e.getMessage());
        }
    }

    /**
     * 获取用户的所有考核记录
     * @param userId 用户ID
     * @return 用户考核历史
     */
    @GetMapping("/history")
    public JsonResult getAssessmentHistory(@RequestParam Integer userId) {
        try {
            List<UserAssessment> history = userAssessmentService.getAssessmentHistory(userId);
            return JsonResult.success(history, "查询成功");
        } catch (Exception e) {
            return JsonResult.error("查询失败: " + e.getMessage());
        }
    }
}
